Page({
    data: {
        value: '',
        id: '',
        week: '',
        num: '',
        day: '',
        xState: false,
        color:'',
        icon:'',
        current:1,
        is_synchronize:true,
        is_anonymous:true,
        treatment_item_id:'',
        days:'',
        type:''
    },

    onLoad: function (opt) {
        this.xToset(opt.title)
        this.setData({
            week: opt.week,
            num: opt.num,
            title: opt.title,
            id: opt.id,
            treatment_item_id:opt.treatment_item_id,
            days:opt.day,
            type:Number(opt.type)
        })
        wx.setNavigationBarTitle({
            title: opt.title,
        })
        this.xTepInit(opt.num)
    },
    onShareAppMessage: function () {
      return {
        title: this.data.day.writing_class_name +'练习'
      };
    },
    xToset: function (title){
      switch(title) {
        case "情绪日记":
          this.setData({
            color:'background-color:#E6F2FF',
            icon:'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/qxrj.png'
          })
        break;
        case "焦虑情绪日记":
          this.setData({
            color:'background-color:#FAD9D9',
            icon:'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/jlqxrj.png'
          })
        break;
        case "思想日记":
            this.setData({
              color:'background-color:#D5EBE9',
              icon:'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/sxrj.png'
            })
        break;
        case "管理反刍式思维":
            this.setData({
              color:'background-color:#FFEDD5',
              icon:'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/glrj.png'
            })
        break;
        case "认知日记":
            this.setData({
              color:'background-color:#E6E6FF',
              icon:'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/rzrj.png'
            })
        break;
        case "行为日记":
            this.setData({
              color:'background-color:#EEE7F4',
              icon:'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/xwrj.png'
            })
        break;
        default:
            this.setData({
              color:'background-color:#FAD9D9',
              icon:'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/khrj.png'
            })
      } 
    },
    xTepInit: function (id) {
        let that = this
        let _dataObj ={
            parameter_id: id
        }
        wx.cloud.callFunction({
            name: 'digital_therapy',
            data: {
                action: "get_write_task_info",
                dataObj: _dataObj
            }
        }).then(res => {
            console.log("返回数据:", res)
            let data = res.result
            that.setData({
                day : data
            })
            var str = data.writing_class_desc.split("\n")
            that.setData({
               ['day.writing_class_desc']:str
            })
        })
    },

    xSub: function () {
      console.log(this.data.days)
      wx.navigateTo({
        url: '/subtool/pages/dayremb/detail/index?id=' + this.data.id + '&num=' + this.data.num + '&week='+ this.data.week+ '&title=' + this.data.title+'&color='+this.data.color+'&icon='+this.data.icon+'&day='+ this.data.days+'&treatment_item_id='+this.data.treatment_item_id
      })
    },

})